// <copyright file="CleverCmsController.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Web.Controllers
{
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;

    using CleverCMS.Core;
    using CleverCMS.Core.Web;
    using CleverCMS.Cms.Data.Entities;

    public class CleverCmsController : Controller
    {
        protected string GetWebsiteUrl()
        {
            HttpRequestBase request = HttpContext.Request;
            return Utils.GetBaseUrl(request.ApplicationPath,  request.Url, true);
        }

        public static RouteValueDictionary GetRouteValues(CmsPage entry)
        {
            if (null == entry)
                return new RouteValueDictionary();

            return new RouteValueDictionary(new {id = entry.Id, name = entry.Alias});
        }

        protected string GenerateEntryUrl(CmsPage entry)
        {
            return VirtualPathUtility.RemoveTrailingSlash(this.GetWebsiteUrl()) +  Url.Action("Content", "Home", GetRouteValues(entry));
        }
    }
}